package com.java.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.java.entity.RaceInfo;
import com.java.service.RaceInfomationService;
import com.java.util.resp.BaseRespone;
import com.java.util.resp.TableRespone;
import com.java.util.servlet.ServletUtil;

@RestController
//@RequestMapping("/infomation")
public class RaceInfomationController {

	@Autowired
	private RaceInfomationService infomationService;
	
	@PostMapping("/createInfo")
	public BaseRespone createInfo(@RequestBody RaceInfo info) {
		info.setInfoPublishId(ServletUtil.getUserId(null));
		return infomationService.createInfo(info);
	}

	@PostMapping("/upodateInfo")
	public BaseRespone upodateInfo(@RequestBody RaceInfo info) {
		return infomationService.upodateInfo(info);
	}

	@PostMapping("/delInfo")
	public BaseRespone delInfo(@RequestParam(required = false) String infoId) {
		return infomationService.delInfo(infoId);
	}

	@PostMapping("/getInfos")
	public TableRespone getInfos(@RequestParam(required = false) String userId,
			@RequestParam(required = false, defaultValue = "0") int page,
			@RequestParam(required = false, defaultValue = "0") int size) {
		return infomationService.getInfos(ServletUtil.getUserId(userId), page, size);
	}
}
